<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #box {
            margin: 200px auto;
            padding: 50px;
            height: 200px;
            width: 200px;
            border: 1px solid black;
            /* 设置perspective属性，使内部元素获得透视效果 */
            perspective: 800px;
        }
        #div {
            /* 给要进行3d变换的div设置一个相对定位的父元素 */
            position: relative;
            height: 200px;
            width: 200px;
            transform-style: preserve-3d;
            transition: 3s;
        }
        #box:hover #div {
            transform: rotateY(-360deg);
        }
        #div div {
            position: absolute;
            width: 200px;
            height:200px;
            font: 100px/200px "宋体";
            text-align: center;
            color: #fff;
            opacity: 0.4;
            transition: 3s;
        }
        #div .a{
            width: 100px;
            height: 100px;
            font: 50px/100px "宋体";
            top: 50px;
            left: 50px;
        }
        #div div:nth-of-type(1) {
            background-color: rebeccapurple;
            /* 设置延申之后的大小 */
            transform: rotateY(0deg) translateZ(100px);
        }
        #div div:nth-of-type(2) {
            background-color: skyblue;
            transform: rotateY(90deg) translateZ(100px);
        }
        #div div:nth-of-type(3) {
            background-color: rgb(238, 238, 111);
            transform: rotateY(180deg) translateZ(100px);
        }
        #div div:nth-of-type(4) {
            background-color:tomato;
            transform: rotateY(270deg) translateZ(100px);
        }
        #div div:nth-of-type(5) {
            background-color: springgreen;
            transform: rotateX(90deg) translateZ(100px);
        }
        #div div:nth-of-type(6) {
            background-color: pink;
            transform: rotateX(-90deg) translateZ(100px);
        }

        #box:hover #div div:nth-of-type(1) {
            transform: translateZ(300px);
        }
        #box:hover #div div:nth-of-type(2) {
            transform: rotateY(90deg) translateZ(200px);
        } 
         #box:hover #div div:nth-of-type(3) {
            transform: rotateY(180deg) translateZ(200px);
        }  
        #box:hover #div div:nth-of-type(4) {
            transform: rotateY(270deg) translateZ(200px);
        }
        #box:hover #div div:nth-of-type(5) {
            transform: rotateX(90deg) translateZ(200px);
        }
        #box:hover #div div:nth-of-type(6) {
            transform: rotateX(-90deg) translateZ(200px);
        }

        #div div:nth-of-type(7) {
            background-color: rebeccapurple;
            /* 设置延申之后的大小 */
            transform: rotateY(0deg) translateZ(50px);
        }
        #div div:nth-of-type(8) {
            background-color: skyblue;
            transform: rotateY(90deg) translateZ(50px);
        }
        #div div:nth-of-type(9) {
            background-color: rgb(238, 238, 111);
            transform: rotateY(180deg) translateZ(50px);
        }
        #div div:nth-of-type(10) {
            background-color:tomato;
            transform: rotateY(270deg) translateZ(50px);
        }
        #div div:nth-of-type(11) {
            background-color: springgreen;
            transform: rotateX(90deg) translateZ(50px);
        }
        #div div:nth-of-type(12) {
            background-color: pink;
            transform: rotateX(-90deg) translateZ(50px);
        }

    </style>
</head>
<body>
    <div id="box">
        <div id="div">
            <div>1</div>
            <div>2</div>
            <div>3</div>
            <div>4</div>
            <div>5</div>
            <div>6</div>
            <div class="a">1</div>
            <div class="a">2</div>
            <div class="a">3</div>
            <div class="a">4</div>
            <div class="a">5</div>
            <div class="a">6</div>
        </div>
    </div>
</body>
</html>